package com.sneakxy.actions;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.sneakxy.config.Config;

public class ActionIndex implements Action {
	
	@Override
	public void execute(CommandLine command, Options options) throws Exception {
		final Config config = createConfig(command, options);
		int size = config.getIndex().getSize();
		String value = StringUtils.trimToEmpty(config.getIndex().getValue());
		int hashCode = new HashCodeBuilder().append(value).toHashCode();
		int index = Math.abs(hashCode) % size;
		System.out.println(StringUtils.join("序号：", index));
	}

}
